package com.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.utils.Page;
import com.dao.AdminDao;
import com.entity.Admin;
import org.apache.commons.lang3.StringUtils;
import com.service.AdminService;
/**
 * 用户Service接口实现类
 */
@Service("adminService")
@Transactional
public class AdminServiceImpl implements AdminService{

	// 注入AdminDao
	@Autowired
	private AdminDao adminDao;
	@Override
	public Admin findAdminname(String admin_name) {
		// TODO Auto-generated method stub
		Admin admin=adminDao.findAdminname(admin_name);
		return admin;
	}

	@Override
	public Admin findAdmin(String admin_name, String password) {
		// TODO Auto-generated method stub
		Admin admin=adminDao.findAdmin(admin_name,password);
		return admin;
	}

	@Override
	public Admin getAdminById(Integer id) {
		// TODO Auto-generated method stub
		return adminDao.getAdminById(id);
	}

	@Override
	public Page<Admin> findAdminList(Integer page, Integer rows, String admin_name) {


		// 创建客户对象
         Admin admin = new Admin();
 		if(StringUtils.isNotBlank(admin_name)){
			admin.setAdmin_name(admin_name);
		}
		// 当前页
		admin.setStart((page-1) * rows) ;
		// 每页数
		admin.setRows(rows);
		// 查询客户列表
		List<Admin> admins = adminDao.selectAdminList(admin);
		// 查询客户列表总记录数
		Integer count = adminDao.selectAdminListCount(admin);
		Page<Admin> result = new Page<>();
		result.setPage(page);
		result.setRows(admins);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}

	@Override
	public int createAdmin(Admin admin) {
		return adminDao.createAdmin(admin);
	}

	@Override
	public int deleteAdmin(Integer id) {
		// TODO Auto-generated method stub
		return adminDao.deleteAdmin(id);
	}

	@Override
	public int updateAdmin(Admin admin) {
		// TODO Auto-generated method stub
		return adminDao.updateAdmin(admin);
	}

	
	
}
